package com.wjtc.common.base.restful;

import com.wjtc.common.base.restful.enums.RtCodeType;
import com.wjtc.common.base.restful.inter.BaseReturn;
import com.wjtc.common.consts.AppConsts;
import com.wjtc.common.utils.JsonUtil;

/**
 * Restful返回对象,抽象类
 * @author G20
 *
 */
public class RtMsg implements BaseReturn{

	private Integer code;

	private String msg;

	private Object responseBody;

	public RtMsg(){
		code = AppConsts.RT_CODE_SUCCESS;
		msg = AppConsts.RT_MSG_SUCCESS;
	}


	public Integer getCode() {
		return code;
	}

	public RtMsg setCode(RtCodeType type) {
		if(type.getIndex() == AppConsts.RT_CODE_VALIDATOR){
			msg = "校验异常.";
		}else if(type.getIndex() == AppConsts.RT_CODE_SUCCESS){
			msg = "操作成功.";
		}else if(type.getIndex() == AppConsts.RT_CODE_ERROR){
			msg = "后台异常.";
		}
		code = type.getIndex();
		return this;
	}

	public String getMsg() {
		return msg;
	}

	public RtMsg setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public Object getResponseBody() {
		return responseBody;
	}

	public void setResponseBody(Object responseBody) {
		this.responseBody = responseBody;
	}

	@Override
	public String toString(){
		try {
			return JsonUtil.toJSONStringJackson(this);
		} catch (Exception e) {
			return null;
		}

	}
}
